package tomasulo;

import java.util.HashMap;
import java.util.Map;

import tomasulo.component.*;
import tomasulo.ui.MainFrame;
import tomasulo.unit.*;

public class Driver {
	
	private static MainFrame frame = null;
	private static Map<String, Float> cdb = null;
	private static FLOS flos = null;
	private static CPU cpu = null;
	private static final int FU_COUNT = 10;
	private static FU fu = null;
	private static Adder add1 = null;
	private static Adder add2 = null;
	private static Adder add3 = null;
	private static Multiplier mult1 = null;
	private static Multiplier mult2 = null;
	private static Storer store1 = null;
	private static Storer store2 = null;
	private static Storer store3 = null;
	private static Loader load1 = null;
	private static Loader load2 = null;
	private static Loader load3 = null;
	private static Memory memory = null;
	
	public static Float getCDB(String name) {
		return cdb.get(name);
	}
	
	public static Adder getAdder1() {
		return add1;
	}
	
	public static Adder getAdder2() {
		return add2;
	}
	
	public static Adder getAdder3() {
		return add3;
	}
	
	public static Storer getStorer1() {
		return store1;
	}
	
	public static Storer getStorer2() {
		return store2;
	}
	
	public static Multiplier getMultiplier1() {
		return mult1;
	}
	
	public static Multiplier getMultiplier2() {
		return mult2;
	}
	
	public static Storer getStorer3() {
		return store3;
	}
	
	public static Loader getLoader1() {
		return load1;
	}
	
	public static Loader getLoader2() {
		return load2;
	}
	
	public static Loader getLoader3() {
		return load3;
	}
	
	public static Float putCDB(String name, Float f) {
		return cdb.put(name, f);
	}
	
	public static void update() {
		frame.updateUI();
		cdb.clear();
	}
	
	public static FU getFU() {
		return fu;
	}
	
	public static Memory getMemory() {
		return memory;
	}
	
	public static FLOS getFLOS() {
		return flos;
	}
	
	public static CPU getCPU() {
		return cpu;
	}
	
	public static void main(String args[]) {
		cdb = new HashMap<String, Float>();
		flos = new FLOS();
		cpu = new CPU();
		fu = new FU(FU_COUNT);
		add1 = new Adder("Add1");
		cpu.addListener(add1);
		add2 = new Adder("Add2");
		cpu.addListener(add2);
		add3 = new Adder("Add3");
		cpu.addListener(add3);
		mult1 = new Multiplier("Mult1");
		cpu.addListener(mult1);
		mult2 = new Multiplier("Mult2");
		cpu.addListener(mult2);
		store1 = new Storer("Store1");
		cpu.addListener(store1);
		store2 = new Storer("Store2");
		cpu.addListener(store2);
		store3 = new Storer("Store3");
		cpu.addListener(store3);
		load1 = new Loader("Load1");
		cpu.addListener(load1);
		load2 = new Loader("Load2");
		cpu.addListener(load2);
		load3 = new Loader("Load3");
		cpu.addListener(load3);
		memory = new Memory(Memory.DEFAULT_CAPACITY);
		frame = new MainFrame();
	}
	
}
